//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <aura.h>

Aura_Bool AuraTest_Test2()
{
    Aura_Address virAddr = 0;
    Aura_ECode ec = AURA_NOERROR;

    ec = AuraVirtualMemory_Map(0, 0x1000,
                            Aura_MemoryMap_Upgrow,
                            Aura_MemoryProtection_Read,
                            &virAddr);
    if (AURA_FAILED(ec)) {
        Aura_printf(" <AuraTest_Test2> failed. (ec = 0x%x).\n", ec);
        return AURA_FALSE;
    }

    return AURA_TRUE;

}
#if 0



Aura_ECode ec = CVirtualMemory::Alloc(0, uSize, MemoryMap_Upgrow, \
                                    MemoryProtection_Read, &virAddr);
    if (AURA_FAILED(ec)) {
        TPERR("CVirtualMemory::Alloc failed ec= 0x%08x\n", ec);
        return 1;
    }

    ec = CVirtualMemory::CheckProtection(virAddr, MemoryProtection_Read, \
                                        &bIsValid);
    if (AURA_FAILED(ec) || !bIsValid) {
        TPERR("MemoryCheck 1 ec= 0x%08x, IsValid: %d\n", ec, bIsValid);
        goto ErrorExit;
    }
}

int CTest::Test2(int argc, char *argv[])
{
    Address virAddr;
    UINT uSize = 0x1000;
    Boolean bIsValid = AURA_FALSE;
    Address BaseAddr;
    MemorySize querySize;

    Aura_ECode ec = CVirtualMemory::Alloc(0, uSize, MemoryMap_Upgrow, \
                                    MemoryProtection_Read, &virAddr);
    if (AURA_FAILED(ec)) {
        TPERR("CVirtualMemory::Alloc failed ec= 0x%08x\n", ec);
        return 1;
    }

    ec = CVirtualMemory::CheckProtection(virAddr, MemoryProtection_Read, \
                                        &bIsValid);
    if (AURA_FAILED(ec) || !bIsValid) {
        TPERR("MemoryCheck 1 ec= 0x%08x, IsValid: %d\n", ec, bIsValid);
        goto ErrorExit;
    }

    ec = CVirtualMemory::SetProtection(virAddr, uSize, MemoryProtection_Write);
    if (AURA_FAILED(ec)) {
        TPERR("CVirtualMemory::SetProtection failed ec= 0x%08x\n", ec);
        goto ErrorExit;
    }

    ec = CVirtualMemory::CheckProtection(virAddr, MemoryProtection_Write, \
                                        &bIsValid);
    if (AURA_FAILED(ec) || !bIsValid) {
        TPERR("MemoryCheck 2 ec= 0x%08x, IsValid: %d\n", ec, bIsValid);
        goto ErrorExit;
    }

    ec = CVirtualMemory::Commit(virAddr);
    if (AURA_FAILED(ec)) {
        TPERR("MemoryCommit ec= 0x%08x\n", ec);
        goto ErrorExit;
    }

    ec = CVirtualMemory::Query(virAddr, &BaseAddr, &querySize);
    if (AURA_FAILED(ec)) {
        TPERR("CVirtualMemory::Query() failed, ec = 0x%08x.\n", ec);
    }
    else {
        if (querySize != (INT32)uSize) {
            TPERR("CVirtualMemory::Query() failed, ec = 0x%08x.\n", ec);
        }
    }

    ec = CVirtualMemory::Free(virAddr, uSize);
    if (AURA_FAILED(ec)) {
        TPERR("MemoryFree ec= 0x%08x\n", ec);
        return 1;
    }

    TPOK;
    return 0;

ErrorExit:
    CVirtualMemory::Free(virAddr, uSize);
    return 1;
}

#endif
